//
//  SEHospitalDetailDoctorCell.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/6.
//

import UIKit

protocol SEHospitalDetailDoctorCellDelegate: NSObjectProtocol {
    func hospitalDetailDoctorCellBtnAction(model: SEDoctorDetail)
}

class SEHospitalDetailDoctorCell: UITableViewCell {

    static let className = "SEHospitalDetailDoctorCell"
    static let reuseId = className

    @IBOutlet weak var avatorImgView: UIImageView!
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var jobAndDeptLabel: UILabel!
    @IBOutlet weak var goodAtLabel: UILabel!

    @IBOutlet weak var doctorAvatorImgView: UIImageView! {
        didSet {
            doctorAvatorImgView.layer.cornerRadius = doctorAvatorImgView.frame.size.height / 2.0
            doctorAvatorImgView.layer.masksToBounds = true
        }
    }

    @IBOutlet weak var advisoryBtn: UIButton! {
        didSet {
            advisoryBtn.layer.cornerRadius = advisoryBtn.frame.size.height / 2.0
            advisoryBtn.layer.borderWidth = 1
            advisoryBtn.layer.borderColor = Asset.main.color.cgColor
            advisoryBtn.layer.masksToBounds = true
        }
    }

    @IBAction func advisoryBtnAction(_ sender: UIButton) {
        delegate?.hospitalDetailDoctorCellBtnAction(model: model)
    }

    private var model = SEDoctorDetail()
    weak var delegate: SEHospitalDetailDoctorCellDelegate?

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization coder
    }

    func updateData(_ model: SEDoctorDetail) {
        self.model = model
        let placeholder = model.sex == 1 ? Asset.iconDoctorAvatarMale.image : Asset.iconDoctorAvatarFemale.image
        avatorImgView.kf.setAvatarImage(urlString: model.imgUrl,
                                        placeholder: placeholder)
        nameLabel.text = model.name
        jobAndDeptLabel.text = "\(model.jobTitle ?? "")/\(model.deptName ?? "")"
        goodAtLabel.text = model.speciality
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
